#ifndef TCPFILE_H
#define TCPFILE_H

#include <QWidget>
#include <QTcpServer>
#include <QTcpSocket>
#include <QFile>
#include <QTimer>

namespace Ui {
class TCPFile;
}

class TCPFile : public QWidget
{
	Q_OBJECT

public:
	explicit TCPFile(QWidget *parent = nullptr);
	~TCPFile();

	void server();
	void client();
	//发送数据函数
	void server_send_data();
	//获取当前ip地址
	QString gethostIp();
	QString gethostMac();

private slots:
	void on_pushButton_server_choice_file_clicked();

	void on_pushButton_server_send_file_clicked();

	void on_pushButton_client_connect_clicked();

	void on_pushButton_server_bind_port_clicked();

private:
	Ui::TCPFile *ui;

	QTcpServer * tcp_server = nullptr;
	QTcpSocket * tcp_server_socket = nullptr;
	QTcpSocket * tcp_client_socket = nullptr;

	//文件对象
	QFile file_server;
	QFile file_client;
	//服务端获取文件信息使用
	QString file_info_server;
	//防止黏包定时器
	QTimer timer;
	//设置客户端累计发送大小和总大小
	qint64 client_receive_file_size = 0;
	qint64 client_file_size = 0;
	//设置是否为头数据包
	bool is_head = true;
};

#endif // TCPFILE_H
